use "/Users/jimgolby/Desktop/ZB - Confidence Book/Technical Appendix/Data Files/Wave 2.dta"

***Define Variables***
replace Q11 =. if Q11 == 98
generate Q11T =.
replace Q11T = 0 if Q11 > 2
replace Q11T = 1 if Q11 < 3
replace Q11T =. if Q11 ==.

label define Confidence 0 "Not Confident" 1 "Confident"
label values Q11T Confidence

generate Q11H =.
replace Q11H = 0 if Q11 > 1
replace Q11H = 1 if Q11 == 1

generate PID3 =.
replace PID3 = 1 if PARTYID < 4
replace PID3 = 2 if PARTYID == 4
replace PID3 = 3 if PARTYID > 4 & PARTYID < 8

label define PID3 1 "Dem" 2 "Ind" 3 "Rep"
label values PID3 PID3

gen DEM = 0 if PID3 < 4
replace DEM = 1 if PID3 == 1
gen REP = 0 if PID3 < 4
replace REP = 1 if PID3 == 3
gen IND = 0 if PID3 < 4
replace IND = 1 if PID3 == 2

replace IDEO =. if IDEO == 98

gen IDEO3 = .
replace IDEO3 = 1 if IDEO < 4
replace IDEO3 = 2 if IDEO == 4
replace IDEO3 = 3 if IDEO > 4 & IDEO < 8

gen IDEO3a = IDEO3
replace IDEO3a = 4 if IDEO == 8

gen LIB = 0
replace LIB = 1 if IDEO3 == 1
gen MOD = 0
replace MOD = 1 if IDEO3 == 2
gen CON = 0
replace CON = 1 if IDEO3 == 3

gen MALE = 0
replace MALE = 1 if GENDER == 1

gen VET = VETERAN if VETERAN < 98
replace VET = 0 if VETERAN == 2
replace VET = 0 if VETERAN2 == 1
replace VET = . if VETERAN2 == 98


gen ACTIVEDUTY = 0 if VETERAN < 98
replace ACTIVEDUTY = . if VETERAN2 == 98
replace ACTIVEDUTY = 1 if VETERAN2 == 1

generate FAMILY = 0 if Q39 < 77
replace FAMILY = 1 if Q39 == 1

gen SOCIAL = 0 if Q38 < 98
replace SOCIAL = 1 if Q38 == 1

generate religion = 0 if RELIG < 98
replace religion = 1 if RELIG == 1
replace religion = 1 if RELIG == 3
replace religion = 1 if RELIG == 4
replace religion = 1 if RELIG == 12
replace religion = 2 if RELIG == 2
replace religion = 3 if RELIG > 8 & RELIG < 12
label define RELIGION2 0 "Other" 1 "Christian" 2 "Catholic" 3 "None"
label values religion RELIGION2

generate christian = 0
replace christian = 1 if religion == 1
generate catholic = 0
replace catholic = 1 if religion == 2
generate norelig = 0
replace norelig = 1 if religion == 3

generate white = 0
replace white = 1 if RACE == 1
generate black = 0
replace black = 1 if RACE == 2
generate hispanic = 0
replace hispanic = 1 if RACE == 4
generate asian = 0
replace asian = 1 if RACE == 6

gen RACE2 = RACE if RACETHNICITY < 77

label define RACE 1 "White" 2 "Black" 4 "Hispanic" 6 "Asian"
label values RACE2 RACE

generate generation =.
replace generation = 1 if AGE > 73
replace generation = 2 if AGE > 54 & AGE < 74
replace generation = 3 if AGE > 38 & AGE < 55
replace generation = 4 if AGE > 22 & AGE < 39
replace generation = 5 if AGE < 23

label define GENERATION 1 "Silent" 2 "Boomer" 3 "Gen X" 4 "Millennial" 5 "Gen Z"
label values generation GENERATION

generate silent = 0
replace silent = 1 if generation == 1
generate boomer = 0
replace boomer = 1 if generation == 2
generate genx = 0
replace genx = 1 if generation == 3
generate milen = 0
replace milen = 1 if generation == 4
generate genz = 0
replace genz = 1 if generation == 5

gen midwest = 0
replace midwest = 1 if REGION4 == 2
gen south = 0
replace south = 1 if REGION4 == 3
gen west = 0
replace west = 1 if REGION4 == 4

replace URBAN3 =. if URBAN3 < 1
generate city = 0
replace city = 1 if URBAN3 == 1
generate rural = 0
replace rural = 1 if URBAN3 == 3

generate unemployed = 0 if EMPLOY < 3  
replace unemployed = 1 if EMPLOY > 2
replace unemployed = 0 if EMPLOY == 5

generate INCOME5 =.
replace INCOME5 = 1 if INCOME < 5
replace INCOME5 = 2 if INCOME > 4 & INCOME < 9
replace INCOME5 = 3 if INCOME > 8 & INCOME < 12
replace INCOME5 = 4 if INCOME > 11 & INCOME < 15
replace INCOME5 = 5 if INCOME > 14

gen married =.
replace married = 1 if MARITAL == 1
replace married = 0 if MARITAL > 1

gen EDUC3 = . if EDUC5 > 5
replace EDUC3 = 1 if EDUC5 < 3
replace EDUC3 = 2 if EDUC5 == 3
replace EDUC3 = 2 if EDUC5 == 4
replace EDUC3 = 3 if EDUC5 == 5

replace Q14 =. if Q14 > 76
replace Q15 =. if Q15 > 76
replace Q16 =. if Q16 > 76

generate Q14T = 0 if Q14 > 2
replace Q14T = 1 if Q14 < 3

generate Q15T = 0 if Q15 > 2
replace Q15T = 1 if Q15 < 3

generate Q16T = 0 if Q16 > 2
replace Q16T = 1 if Q16 < 3

gen d2 = 0
gen d3 = 0
gen d4 = 0
gen d5 = 0
gen d6 = 0
gen d7 = 0
gen d8 = 0

replace d2 = 1 if P_ASSIGN1 == 2
replace d3 = 1 if P_ASSIGN1 == 3
replace d4 = 1 if P_ASSIGN1 == 4
replace d5 = 1 if P_ASSIGN1 == 5
replace d6 = 1 if P_ASSIGN1 == 6
replace d7 = 1 if P_ASSIGN1 == 7
replace d8 = 1 if P_ASSIGN1 == 8

label define labels121 1 "Print newspaper" 2 "Radio" 3 "Local television" 4 "Natl network TV" 5 "Cable TV" 6 "Social media" 7 "Websites or apps" 77 "DON'T KNOW" 98 "SKIPPED ON WEB" 99 "REFUSED", replace

replace Q32 =. if Q32 > 5

replace Q30A =. if Q30A > 3
replace Q30B =. if Q30B > 3
replace Q30C =. if Q30C > 3
replace Q30D =. if Q30D > 3
replace Q30E =. if Q30E > 3
replace Q30F =. if Q30F > 3
replace Q30G =. if Q30G > 3
replace Q30H =. if Q30H > 3
replace Q30I =. if Q30I > 3

recode Q32 (2=3)(3=2)

label define labels144 1 "From news sources" 2 "From friends & family who served" 3 "From movies & TV shows" 4 "From personal mil experience" 5 "Other" 77 "DON'T KNOW" 98 "SKIPPED ON WEB" 99 "REFUSED", replace

replace Q41 =. if Q41 > 4
generate Q41T =.
replace Q41T = 0 if Q41 > 2 & Q41 < 5
replace Q41T = 1 if Q41 < 3

gen EDUC4 = EDUC5
replace EDUC4 = 4 if EDUC5 == 5

xi I.DEM*EDUC5 I.REP*EDUC5 I.DEM*EDUC4 I.REP*EDUC4, prefix(_I)

replace Q37 =. if Q37 == 98
replace Q38 =. if Q38 == 98
replace Q39 =. if Q39 == 98

gen Q39AA = .
replace Q39AA = 1 if Q39A_1 == 1
replace Q39AA = 2 if Q39A_2 == 1
replace Q39AA = 3 if Q39A_3 == 1
replace Q39AA = 4 if Q39A_4 == 1
replace Q39AA = 5 if Q39A_5 == 1
replace Q39AA = 6 if Q39A_6 == 1

gen Q39FAM = 0 if Q39 < 98
replace Q39FAM = 1 if Q39BA == 1
replace Q39FAM = 2 if Q39BA == 2
replace Q39FAM = 3 if Q39BA == 3
replace Q39FAM = . if Q39BA == 77
replace Q39FAM = 1 if Q39BB == 1
replace Q39FAM = 2 if Q39BB == 2
replace Q39FAM = 3 if Q39BB == 3
replace Q39FAM = . if Q39BB == 77
replace Q39FAM = 1 if Q39BC == 1
replace Q39FAM = 2 if Q39BC == 2
replace Q39FAM = 3 if Q39BC == 3
replace Q39FAM = . if Q39BC == 77
replace Q39FAM = 1 if Q39BD == 1
replace Q39FAM = 2 if Q39BD == 2
replace Q39FAM = 3 if Q39BD == 3
replace Q39FAM = . if Q39BD == 77
replace Q39FAM = 1 if Q39BE == 1
replace Q39FAM = 2 if Q39BE == 2
replace Q39FAM = 3 if Q39BE == 3
replace Q39FAM = . if Q39BE == 77
replace Q39FAM = 1 if Q39BF == 1
replace Q39FAM = 2 if Q39BF == 2
replace Q39FAM = 3 if Q39BF == 3
replace Q39FAM = . if Q39BF == 77

gen Q39FAM1 = 0 if Q39FAM < 4
replace Q39FAM1 = 1 if Q39 == 1

gen Q39FAMpre = 0 if Q39FAM < 4
replace Q39FAMpre = 1 if Q39FAM == 1
gen Q39FAMpost = 0 if Q39FAM < 4
replace Q39FAMpost = 1 if Q39FAM == 2
gen Q39FAMboth = 0 if Q39FAM < 4
replace Q39FAMboth = 0 if Q39FAM == 2
replace Q39FAMboth = 1 if Q39FAM == 3

gen Q39FAM2pre = 0 if Q39FAM < 4
replace Q39FAM2pre = 1 if Q39FAM == 1
gen Q39FAM2post = 0 if Q39FAM < 4
replace Q39FAM2post = 1 if Q39FAMpost == 1
replace Q39FAM2post = 1 if Q39FAMboth == 1

gen Q17A3 = Q17A if Q17A < 4

gen Q17AR = 0 if Q17A3 < 4
replace Q17AR = 1 if Q17A3 == 2

gen Q17AREP = Q17AR
replace Q17AREP = 0 if Q17B == 1
replace Q17AREP = 0 if Q17B == 3
replace Q17AREP = 1 if Q17B == 2
********************

********************
logit Q11T DEM REP IDEO3 MALE ACTIVEDUTY VET FAMILY SOCIAL catholic christian norelig white black hispanic asian EDUC5 boomer genx milen genz midwest south west city rural unemployed INCOME5 married d2 d3 d4 d5 d6 d7 d8 [pweight = weight2]

*****Figure 3.3*****
logit Q11T DEM REP IDEO3 MALE ACTIVEDUTY VET FAMILY SOCIAL catholic christian norelig white black hispanic asian EDUC5 _IREPXEDUC5_1 _IDEMXEDUC5_1 boomer genx milen genz midwest south west city rural unemployed INCOME5 married d2 d3 d4 d5 d6 d7 d8 [pweight = weight2]

margins, at(DEM=1 REP=0 EDUC5=1 _IREPXEDUC5_1=0 _IDEMXEDUC5_1=1) at(DEM=1 REP=0 EDUC5=2 _IREPXEDUC5_1=0 _IDEMXEDUC5_1=2) at(DEM=1 REP=0 EDUC5=3 _IREPXEDUC5_1=0 _IDEMXEDUC5_1=3) at(DEM=1 REP=0 EDUC5=4 _IREPXEDUC5_1=0 _IDEMXEDUC5_1=4) at(DEM=1 REP=0 EDUC5=5 _IREPXEDUC5_1=0 _IDEMXEDUC5_1=5) post
est store Dem1

logit Q11T DEM REP IDEO3 MALE ACTIVEDUTY VET FAMILY SOCIAL catholic christian norelig white black hispanic asian EDUC5 _IREPXEDUC5_1 _IDEMXEDUC5_1 boomer genx milen genz midwest south west city rural unemployed INCOME5 married d2 d3 d4 d5 d6 d7 d8 [pweight = weight2]
margins, at(DEM=0 REP=1 EDUC5=1 _IREPXEDUC5_1=1 _IDEMXEDUC5_1=0) at(DEM=0 REP=1 EDUC5=2 _IREPXEDUC5_1=2 _IDEMXEDUC5_1=0) at(DEM=0 REP=1 EDUC5=3 _IREPXEDUC5_1=3 _IDEMXEDUC5_1=0) at(DEM=0 REP=1 EDUC5=4 _IREPXEDUC5_1=4 _IDEMXEDUC5_1=0) at(DEM=0 REP=1 EDUC5=5 _IREPXEDUC5_1=5 _IDEMXEDUC5_1=0) post
est store Rep1

coefplot Dem1 Rep1, vertical lwidth(*0.5) connect(l) ytitle(% Answering Correctly) ytitle(, size(medsmall)) yscale(range(0 1)) ylabel(0(.2)1, nogrid) ymtick(, nogrid glcolor()) graphregion(fcolor(white) lcolor(white) lalign(outside) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside) ifcolor(white) ilcolor(white)) subtitle(Education Level, size(medsmall) color(black) position(6)) name(edconf, replace)

*****Figure 3.4*****
logit Q17AREP DEM REP IDEO3 MALE ACTIVEDUTY VET FAMILY SOCIAL catholic christian norelig white black hispanic asian EDUC5 _IREPXEDUC5_1 _IDEMXEDUC5_1 boomer genx milen genz midwest south west city rural unemployed INCOME5 married d2 d3 d4 d5 d6 d7 d8 [pweight = weight2]
margins, at(DEM=1 REP=0 EDUC5=1 _IREPXEDUC5_1=0 _IDEMXEDUC5_1=1) at(DEM=1 REP=0 EDUC5=2 _IREPXEDUC5_1=0 _IDEMXEDUC5_1=2) at(DEM=1 REP=0 EDUC5=3 _IREPXEDUC5_1=0 _IDEMXEDUC5_1=3) at(DEM=1 REP=0 EDUC5=4 _IREPXEDUC5_1=0 _IDEMXEDUC5_1=4) at(DEM=1 REP=0 EDUC5=5 _IREPXEDUC5_1=0 _IDEMXEDUC5_1=5) post
est store Dem2

logit Q17AREP DEM REP IDEO3 MALE ACTIVEDUTY VET FAMILY SOCIAL catholic christian norelig white black hispanic asian EDUC5 _IREPXEDUC5_1 _IDEMXEDUC5_1 boomer genx milen genz midwest south west city rural unemployed INCOME5 married d2 d3 d4 d5 d6 d7 d8 [pweight = weight2]
margins, at(DEM=0 REP=1 EDUC5=1 _IREPXEDUC5_1=1 _IDEMXEDUC5_1=0) at(DEM=0 REP=1 EDUC5=2 _IREPXEDUC5_1=2 _IDEMXEDUC5_1=0) at(DEM=0 REP=1 EDUC5=3 _IREPXEDUC5_1=3 _IDEMXEDUC5_1=0) at(DEM=0 REP=1 EDUC5=4 _IREPXEDUC5_1=4 _IDEMXEDUC5_1=0) at(DEM=0 REP=1 EDUC5=5 _IREPXEDUC5_1=5 _IDEMXEDUC5_1=0) post
est store Rep2

coefplot Dem2 Rep2, vertical lwidth(*0.5) connect(l) ytitle(% Answering Correctly) ytitle(, size(medsmall)) yscale(range(0 1)) ylabel(0(.2)1, nogrid) ymtick(, nogrid glcolor()) graphregion(fcolor(white) lcolor(white) lalign(outside) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside) ifcolor(white) ilcolor(white)) subtitle(Education Level, size(medsmall) color(black) position(6)) name(edparty, replace)

*****Figure 3.5*****
graph bar [pweight = weight2] if Q29 < 8, over(Q29, label(angle(vertical) labsize(vsmall))) blabel(bar, format(%3.0f)) bar(1, fcolor(gs12) lcolor(black)) ytitle(% of Respondents) ytitle(, size(medsmall)) yscale(range(0 30)) ylabel(0(10)30, nogrid) ymtick(, nogrid glcolor()) graphregion(fcolor(white) lcolor(white) lalign(outside) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside) ifcolor(white) ilcolor(white)) subtitle(Primary Political News Source, size(medsmall) color(black) position(6))

*****Figure 3.6*****
graph bar (mean) Q11T [pweight = weight2] if P_ASSIGN1 == 1 & Q29 < 8, over(Q29, label(angle(vertical) labsize(vsmall))) blabel(bar, format(%3.2f)) bar(1, fcolor(gs12) lcolor(black)) ytitle(% Expressing Confidence in the Military) ytitle(, size(medsmall)) yscale(range(0 1)) ylabel(0(0.2)1, nogrid) ymtick(, nogrid glcolor()) graphregion(fcolor(white) lcolor(white) lalign(outside) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside) ifcolor(white) ilcolor(white)) subtitle(Primary Political News Source, size(medsmall) color(black) position(6))

*****Table 3.3*****
tab Q11T Q30A if P_ASSIGN1 == 1 [aweight=weight], column
tab Q11T Q30B if P_ASSIGN1 == 1 [aweight=weight], column
tab Q11T Q30C if P_ASSIGN1 == 1 [aweight=weight], column
tab Q11T Q30D if P_ASSIGN1 == 1 [aweight=weight], column
tab Q11T Q30E if P_ASSIGN1 == 1 [aweight=weight], column
tab Q11T Q30F if P_ASSIGN1 == 1 [aweight=weight], column
tab Q11T Q30G if P_ASSIGN1 == 1 [aweight=weight], column
tab Q11T Q30H if P_ASSIGN1 == 1 [aweight=weight], column
tab Q11T Q30I if P_ASSIGN1 == 1 [aweight=weight], column

*****Figure 3.7*****
graph bar [pweight = weight2], over(Q32, label(angle(vertical) labsize(vsmall))) blabel(bar, format(%3.0f)) bar(1, fcolor(gs12) lcolor(black)) ytitle(% of Respondents) ytitle(, size(medsmall)) yscale(range(0 50)) ylabel(0(10)50, nogrid) ymtick(, nogrid glcolor()) graphregion(fcolor(white) lcolor(white) lalign(outside) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside) ifcolor(white) ilcolor(white)) subtitle(Main Way of Learning About Military, size(medsmall) color(black) position(6))

*****Figure 3.8*****
graph bar (mean) Q11T [pweight = weight2], over(Q32, label(angle(vertical) labsize(vsmall))) blabel(bar, format(%3.2f)) bar(1, fcolor(gs12) lcolor(black)) ytitle(% Expressing Confidence in the Military) ytitle(, size(small)) yscale(range(0 1)) ylabel(0(0.2)1, nogrid) ymtick(, nogrid glcolor()) graphregion(fcolor(white) lcolor(white) lalign(outside) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside) ifcolor(white) ilcolor(white)) subtitle(Main Way of Learning About the Military, size(small) color(black) position(6))

*****Figure 3.9*****
graph bar (mean) Q11T [pweight = weight2] if Q33 < 77, over(Q33, label(angle(vertical) labsize(vsmall))) blabel(bar, format(%3.2f)) bar(1, fcolor(gs12) lcolor(black)) ytitle(% Expressing Confidence in the Military) ytitle(, size(small)) yscale(range(0 1)) ylabel(0(0.2)1, nogrid) ymtick(, nogrid glcolor()) graphregion(fcolor(white) lcolor(white) lalign(outside) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside) ifcolor(white) ilcolor(white)) subtitle(How Closely Following Military News, size(small) color(black) position(6))

logit Q11T Q33 DEM REP IDEO3 MALE ACTIVEDUTY VET FAMILY SOCIAL catholic christian norelig white black hispanic asian EDUC5 boomer genx milen genz midwest south west city rural unemployed INCOME5 married d2 d3 d4 d5 d6 d7 d8 [pweight = weight2] if Q33 < 77

*****Figure 3.10*****
graph bar (mean) Q39FAM1 Q39FAMpre Q39FAMpost Q39FAMboth [pweight = weight], over(generation) blabel(bar, format(%3.2f)) bar(1, fcolor(gs12) lcolor(black)) bar(2, fcolor(gs13) lcolor(black)) bar(3, fcolor(gs14) lcolor(black)) bar(4, fcolor(gs15) lcolor(black)) ytitle(% of Respondents) ytitle(, size(medsmall)) yscale(range(0 1)) ylabel(0(0.2)1, nogrid) ymtick(, nogrid glcolor()) graphregion(fcolor(white) lcolor(white) lalign(outside) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside) ifcolor(white) ilcolor(white)) subtitle(Family Connections to the Military, size(medsmall) color(black) position(6)) name(conf1, replace)

******Personal Contacts*******
mean Q11T if Q41 < 5 [pweight=weight2]
mean Q41T [pweight=weight2]

gen DC = Q41T - Q11T
graph bar (mean) DC [pweight = weight2], over(Q11) blabel(bar, format(%3.2f)) bar(1, fcolor(gs12) lcolor(black)) ytitle(Change In Confidence When Excluding Personal Contacts) ytitle(, size(small)) yscale(range(-0.4 0.4)) ylabel(-0.4(0.2)0.4, nogrid) ymtick(, nogrid glcolor()) graphregion(fcolor(white) lcolor(white) lalign(outside) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(black) lalign(outside) ifcolor(white) ilcolor(white)) subtitle(Confidence in the Military, size(small) color(black) position(6)) yline(0)
********************
